package com.rfid.assistant.activity;

import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.rfid.assistant.R;

public class HomeActivity extends AppCompatActivity {

    public static void startActivity(Context context) {
        startActivity(context,false);
    }

    public static void startActivity(Context context,boolean send) {
        Intent intent = new Intent();
        intent.putExtra("send",send);
        intent.setClass(context,HomeActivity.class);
        context.startActivity(intent);
    }

    boolean isSend;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_layout);
//        askForPermissions();
        isSend = getIntent().getBooleanExtra("send",false);
        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},101);
    }

    public void wlan(View view) {
        if (isSend) {
            WlanAcitivty.startActivity(HomeActivity.this,isSend);
            return;
        }
        new AlertDialog.Builder(this)
                .setMessage("刷脸开门使用本方案有些不稳定，可能需要多次尝试")
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        WlanAcitivty.startActivity(HomeActivity.this,isSend);
                    }
                }).show();
    }

    public void localNet(View view) {
        if (isSend) {
            UdpActivity.startActivity(HomeActivity.this,isSend);
            return;
        }
        new AlertDialog.Builder(this)
                .setMessage("本方案需确保刷脸开门与手机在同一个局域网内")
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        UdpActivity.startActivity(HomeActivity.this,isSend);
                    }
                }).show();
    }

    public void bluetooth(View view) {
        if (isSend) {
            BluetoothMainActivity.startActivity(HomeActivity.this,isSend);
            return;
        }
        new AlertDialog.Builder(this)
                .setMessage("刷脸开门启动后长按右上角进入蓝牙配置界面，然后用此app扫码连接，第一次建立连接的时候需要配对，刷脸开门左上角状态栏下拉点击同意配对。")
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        BluetoothMainActivity.startActivity(HomeActivity.this,isSend);
                    }
                }).show();

    }

    public void remote(View view) {
        RemoteMainActivity.startActivity(this,!isSend);
    }

}
